<?php
class Show
{
	static $hdl400;
	static $hdl500;
	
	static $hdlnot;
	static $hdlerr;
	
	static function error($msg, $jump='', $timeout=0)
	{
		if(self::$hdlerr)
		{
			import('$/controller/'.self::$hdlerr[0].'.php');
			call_user_func(array(ucfirst(self::$hdlerr[0]).'Controller', self::$hdlerr[1]), $msg, self::url($jump), $timeout);
		}
		else
		{
			throw new Exception($msg);
		}
		die;
	}
	static function notice($msg, $jump='', $timeout=0)
	{
		if(self::$hdlnot)
		{
			import('$/controller/'.self::$hdlnot[0].'.php');
			call_user_func(array(ucfirst(self::$hdlnot[0]).'Controller', self::$hdlnot[1]), $msg, self::url($jump), $timeout);
		}
		else
		{
			echo "Notice: $msg <br/>\n";
			if($jump)
			{
				echo '<a href="'.($jump).'">跳转</a>';
			}
		}
		die;
	}
	
	static function go400($msg=null)
	{
		header("HTTP/1.0 404 Page not available");
		null===$msg ? $msg="Page not available, {$_REQUEST['a']} - <i>[error in 404]</i>" : null;
		if(self::$hdl400)
		{
			import('$/controller/'.self::$hdl400[0].'.php');
			call_user_func(array(ucfirst(self::$hdl400[0]).'Controller', self::$hdl400[1]), $msg);
		}
		else
		{
			echo $msg;
		}
		die;
	}
	static function go500($msg='Internal server error')
	{
		header("HTTP/1.0 500 Internal server error");
		if(self::$hdl500)
		{
			import('$/controller/'.self::$hdl500[0].'.php');
			call_user_func(array(ucfirst(self::$hdl500[0]).'Controller', self::$hdl500[1]), $msg);
		}
		else
		{
			echo "<h3>500 - $msg</h3>";
		}
		die;
	}
	
	static protected function url($str)
	{
		return ($str=='self') ?$_SERVER['REQUEST_URI']: Lib::url($str);
	}
	
}
?>